package com.lyw.wechatkf.service;

import com.lyw.wechatkf.config.properties.BaseWeComProperties;
import com.qq.weixin.mp.aes.AesException;
import com.qq.weixin.mp.aes.WXBizMsgCrypt;
import org.springframework.stereotype.Service;

@Service
public class UrlTestService {
    private final BaseWeComProperties baseWeComProperties;

    public UrlTestService(BaseWeComProperties baseWeComProperties) {
        this.baseWeComProperties = baseWeComProperties;
    }

    /**
     * 通过传递过来的字符串进行解密
     * @return
     */
    public String decrypt(String msg_signature,
                           String timestamp,
                           String nonce,
                           String echostr){
        try {
            WXBizMsgCrypt wxBizMsgCrypt = new WXBizMsgCrypt(baseWeComProperties.getSToken(), baseWeComProperties.getSEncodingAESKey(), baseWeComProperties.getSCorpID());
            String res = wxBizMsgCrypt.VerifyURL(msg_signature, timestamp, nonce, echostr);
            System.out.println("verifyurl echostr: " + res);
            return res;
        } catch (AesException e) {
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
